package com.panshi.servers.impl;

import com.panshi.mapper.UserCollectionMapper;
import com.panshi.pojo.UserCollectionVO;
import com.panshi.servers.UserCollectionServers;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

/**
 * @author XiaoWangYa
 * @version 1.0
 * @date 2020/8/8 0008 下午 2:50
 */
@Service
@Api("文章收藏Servers层")
public class UserCollectionServersImpl implements UserCollectionServers {

    @Autowired
    private UserCollectionMapper userCollectionMapper;

    @Override  // 用户收藏文章
    @CacheEvict(value = "collection", allEntries = true)
    public void addUserCollectionInfo(UserCollectionVO userCollectionVO) {
        userCollectionMapper.addUserCollectionInfo(userCollectionVO);
    }

    @Override  // 用户取消收藏文章
    @CacheEvict(value = "collection", allEntries = true)
    public void userCancelArticleCollection(UserCollectionVO userCollectionVO) {
        userCollectionMapper.userCancelArticleCollection(userCollectionVO);
    }

    @Override  // 查询用户是否收藏指定文章
    @Cacheable(value = "collection", key = "#root.methodName + #p0.aid")
    public UserCollectionVO queryUserIFCollectionAtricle(UserCollectionVO userCollectionVO) {
        return userCollectionMapper.queryUserIFCollectionAtricle(userCollectionVO);
    }
}
